const fs = require('fs')
const path = require('path')

module.exports = {
	sleep(sec) {
		return new Promise((resolve, reject) => {
			sec = parseInt(sec) || 1000
			setTimeout(() => resolve(true), sec)
		});
	},

	mkdirsSync(dirPath) {
		if (!fs.existsSync(dirPath)) {
			let pathTmp = ''
			let dirPathArr = dirPath.split(path.sep)
			for (let i = 0; i < dirPathArr.length; i++) {
				let dirname = dirPathArr[i]
				if (!dirname)
					dirname = path.sep;
				if (pathTmp) {
					pathTmp = path.join(pathTmp, dirname);
				} else {
					pathTmp = dirname;
				}
				if (!fs.existsSync(pathTmp)) {
					fs.mkdirSync(pathTmp)
				}
			}
		}
		return true;
	},

}